home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
digsby
/
videochat.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
12KB
|
291 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from __future__ import with_statement
from functools import wraps
from hashlib import md5
from operator import attrgetter
from digsby.web import DigsbyHttp, DigsbyHttpError
from contacts.buddyinfo import BuddyInfo
from common import profile, netcall
from util import threaded, traceguard, Delegate
import wx
from logging import getLogger
log = getLogger('videochat')
INVITE_URL = 'http://v.digsby.com/?id=%(video_token)s&wid=%(widget_id)s'
EMBED_TAG = '<object type="application/x-shockwave-flash" data="http://www.tokbox.com/f/%(widget_id)s" width="540" height="260"><param name="movie" value="http://www.tokbox.com/f/%(widget_id)s"></param><param name=FlashVars value="user=%(user_id)s&pass=%(md5password)s&meebo=true&onsite=false"></param></object>'
def tokbox_url(widget_id, user_id, md5password):
return 'http://www.tokbox.com/f/%s?user=%s&pass=%s&meebo=true&onsite=false' % (widget_id, user_id, md5password)
VIDEO_USERID_PREF = 'digsby.webvideo.user_id'
VIDEO_WIDGETID_PREF = 'digsby.webvideo.widget_id'
def get_video_ids():
pref = pref
import common
user_id = pref(VIDEO_USERID_PREF, '', type = str)
widget_id = pref(VIDEO_WIDGETID_PREF, '', type = str)
if not user_id:
widget_id = ''
elif not widget_id:
user_id = ''
return (user_id, widget_id)
def save_video_ids(user_id, widget_id):
if not all((lambda .0: for a in .0:
if isinstance(a, str):
passa)((user_id, widget_id))):
raise TypeError('save_video_ids takes two non empty strings')
profile.prefs[VIDEO_USERID_PREF] = user_id
profile.prefs[VIDEO_WIDGETID_PREF] = widget_id
class VideoChat(object):
def __init__(self, buddy):
self.buddy_info = BuddyInfo(buddy)
self.http = VideoChatHttp(profile.username, profile.password, *get_video_ids())
self._widget_jid = None
self._stopped = False
self.on_stop = Delegate()
self.handle_buddy_state(buddy)
my_alias = buddy.protocol.self_buddy.name
friend_alias = buddy.name
create = threaded(self.http.create_video)
create(my_alias, friend_alias, success = self.on_token, error = self.error_token)
def handle_buddy_state(self, buddy):
proto = buddy.protocol
def on_protocol_state(proto, attr, old, new):
if not proto.connected:
self.stop()
proto.add_observer(on_protocol_state, 'state', obj = self)
(self, self.on_stop) += (lambda : proto.remove_observer(on_protocol_state, 'state'))
def __repr__(self):
return '<VideoChat with %s>' % self.buddy_info
def on_token(self):
token = self.http.video_token
log.info('received video token: %s', token)
profile.connection.add_video_chat(token, self)
wx.CallAfter(self.on_url, self.http.invite_url(), self.http.embed())
def on_url(self, invite_url, embed_tag):
save_video_ids(self.http.user_id, self.http.widget_id)
buddy = self.buddy_info.buddy()
if buddy is not None:
message = _('Join me in an audio/video call: %s') % invite_url
def send_and_echo_invite():
convo = buddy.protocol.convo_for(buddy)
convo._send_message(message)
convo.system_message(_('You have invited %s to an audio/video chat.') % buddy.name)
netcall(send_and_echo_invite)
title = _('Audio/Video Call with %s' % self.buddy_info.buddy_name)
VideoChatWindow = VideoChatWindow
import gui.video.webvideo
frame = self.video_frame = VideoChatWindow(title, embed_tag, on_close = self.stop)
wx.CallAfter(frame.Show)
def error_token(self):
log.warning('error receiving token')
self.system_message(_('Audio/Video chat is currently unavailable.'))
def send_im(self, message):
convo = self.widget_convo
if convo is not None:
(None, netcall)((lambda : convo._send_message(message)))
def widget_convo(self):
if self.widget_jid is None:
self.widget_jid = self.find_widget_jid()
if self.widget_jid is None:
return log.warning('no widget jid, cannot forward message to widget')
conn = profile.connection
if not conn:
return log.warning('no Digsby connection, cannot forward message to widget')
return conn.convo_for(self.widget_jid)
widget_convo = property(widget_convo)
def set_widget_jid(self, jid):
if jid != self._widget_jid:
self._widget_jid = jid
if profile.connection:
profile.connection.get_buddy(jid).add_observer(self.buddy_status_change, 'status')
widget_jid = property(attrgetter('_widget_jid'), set_widget_jid)
def find_widget_jid(self):
conn = profile.connection
if conn is None:
return log.warning('cannot find widget jid: no digsby connection')
resource = 'video.' + self.http.video_token
for buddict in conn.buddy_dictionaries():
for name, buddy in buddict.iteritems():
if buddy.jid.domain == u'guest.digsby.org':
for jid, res in buddy.resources.iteritems():
if jid.resource == resource:
return jid
continue
def buddy_status_change(self, buddy, attr, old, new):
if buddy.online:
return None
log.info('buddy %r went offline...stopping', buddy)
buddy.remove_observer(self.buddy_status_change, 'status')
if not self._stopped:
self.system_message(_('Audio/Video call ended by other party.'))
self.stop()
def system_message(self, message):
traceguard.__enter__()
try:
im_buddy = self.buddy_info.buddy()
if im_buddy is not None:
convo = im_buddy.protocol.convo_for(im_buddy)
convo.system_message(message)
finally:
pass
def stop(self):
self.stop = lambda *a: pass
self._stopped = True
log.info('stopping video chat %r', self)
if self.video_frame:
wx.CallAfter(self.video_frame.Destroy)
convo = self.widget_convo
if convo is not None:
netcall(self.widget_convo.buddy.appear_offline_to)
token = self.http.video_token
if token is not None:
conn = profile.connection
if conn is not None:
conn.remove_video_chat(token)
threaded(self.http.close_video)()
self.on_stop()
def require_registered(func):
def wrapper(self, *a, **k):
if not self.registered:
log.info('Not registered yet, requesting video user id...')
self.register()
return func(self, *a, **k)
wrapper = (wraps(func),)(wrapper)
return wrapper
def password_hash(p):
for x in xrange(3):
p = md5(p).hexdigest()
return p
class VideoChatException(Exception):
pass
class VideoChatNotRegistered(VideoChatException):
pass
class VideoChatHttp(DigsbyHttp):
def __init__(self, username, password, user_id = None, widget_id = None):
DigsbyHttp.__init__(self, username, password)
self.user_id = user_id
self.widget_id = widget_id
def registered(self):
if self.widget_id:
pass
return self.user_id
registered = property(registered)
def register(self):
resp = self.GET(obj = 'tokbox', act = 'register')
try:
(self.user_id, self.widget_id) = resp.split(':')
except ValueError:
raise DigsbyHttpError('register expected "widget_id:user_id", but received %r' % resp)
log.info('registered (user_id=%r, widget_id=%r)' % (self.user_id, self.widget_id))
def create_video(self, nick, guest):
self.video_token = self.GET(obj = 'widget', act = 'video', wid = self.widget_id, nick = nick.encode('utf-8'), guest = guest.encode('utf-8'))
create_video = require_registered(create_video)
def invite_url(self):
if self.video_token is None:
raise VideoChatException('no AV page has been created')
return INVITE_URL % dict(video_token = self.video_token, widget_id = self.widget_id)
invite_url = require_registered(invite_url)
def embed(self):
return EMBED_TAG % dict(widget_id = self.widget_id, user_id = self.user_id, md5password = password_hash('digsby' + self.username))
embed = require_registered(embed)
def flash_url(self):
return tokbox_url(self.widget_id, self.user_id, password_hash('digsby' + self.username))
flash_url = require_registered(flash_url)
def close_video(self):
log.info('%r.close_video()', self)
self.GET(obj = 'widget', act = 'killvideo')